package com.yuda.campsite.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.yuda.campsite.domain.CampsiteOrder;
import com.yuda.campsite.service.ICampsiteOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yuda.common.log.annotation.Log;
import com.yuda.common.log.enums.BusinessType;
import com.yuda.common.security.annotation.PreAuthorize;

import com.yuda.common.core.web.controller.BaseController;
import com.yuda.common.core.web.domain.AjaxResult;
import com.yuda.common.core.utils.poi.ExcelUtil;
import com.yuda.common.core.web.page.TableDataInfo;

/**
 * 订单Controller
 *
 * @author wyn
 * @date 2021-09-27
 */
@RestController
@RequestMapping("/order")
public class CampsiteOrderController extends BaseController
{
    @Autowired
    private ICampsiteOrderService campsiteOrderService;

    /**
     * 查询订单列表
     */
//    @PreAuthorize(hasPermi = "common:order:list")
    @GetMapping("/list")
    public TableDataInfo list(CampsiteOrder campsiteOrder)
    {
        startPage();
        List<CampsiteOrder> list = campsiteOrderService.selectCampsiteOrderList(campsiteOrder);
        return getDataTable(list);
    }

    /**
     * 导出订单列表
     */
//    @PreAuthorize(hasPermi = "common:order:export")
    @Log(title = "订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CampsiteOrder campsiteOrder) throws IOException
    {
        List<CampsiteOrder> list = campsiteOrderService.selectCampsiteOrderList(campsiteOrder);
        ExcelUtil<CampsiteOrder> util = new ExcelUtil<CampsiteOrder>(CampsiteOrder.class);
        util.exportExcel(response, list, "order");
    }

    /**
     * 获取订单详细信息
     */
//    @PreAuthorize(hasPermi = "common:order:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(campsiteOrderService.selectCampsiteOrderById(id));
    }

    /**
     * 新增订单
     */
//    @PreAuthorize(hasPermi = "common:order:add")
    @Log(title = "订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CampsiteOrder campsiteOrder)
    {
        return toAjax(campsiteOrderService.insertCampsiteOrder(campsiteOrder));
    }

    /**
     * 修改订单
     */
//    @PreAuthorize(hasPermi = "common:order:edit")
    @Log(title = "订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CampsiteOrder campsiteOrder)
    {
        return toAjax(campsiteOrderService.updateCampsiteOrder(campsiteOrder));
    }

    /**
     * 删除订单
     */
//    @PreAuthorize(hasPermi = "common:order:remove")
    @Log(title = "订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(campsiteOrderService.deleteCampsiteOrderByIds(ids));
    }
}
